package com.cxl.bill.server.bean;

import lombok.Data;
import lombok.val;

import java.io.Serializable;

@Data
public class ResponseBean<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    private T data;
    private int code;
    private String message;
    private int pageIndex = 0;
    private int pageTotal = 0;

    public static <T>ResponseBean<T> ok(T data){
        ResponseBean<T> response = new ResponseBean<>();
        response.code = 200;
        response.data = data;
        response.message = "success";
        return response;
    }
    public static <T>ResponseBean<T> ok(T data,int pageIndex,int pageTotal){
        ResponseBean<T> response = new ResponseBean<>();
        response.code = 200;
        response.data = data;
        response.pageIndex = pageIndex;
        response.pageTotal = pageTotal;
        response.message = "success";
        return response;
    }

    public static ResponseBean<Object> ok(){
        ResponseBean<Object> response = new ResponseBean<>();
        response.code = 200;
        response.message = "success";
        return response;
    }

    public static ResponseBean<Object> error(String message,int code){
        ResponseBean<Object> response = new ResponseBean<>();
        response.code = code;
        response.message = message;
        return response;
    }
    public static ResponseBean<Object> error(String message){
        ResponseBean<Object> response = new ResponseBean<>();
        response.code = 444;
        response.message = message;
        return response;
    }
    public static ResponseBean<Object> error(){
        ResponseBean<Object> response = new ResponseBean<>();
        response.code = 444;
        response.message = "error";
        return response;
    }


    @Override
    public String toString() {
        return "{" +
                "\"data\":" + data +
                ", \"code\":" + code +
                ", \"message\":'" + message + '\'' +
                '}';
    }
}
